<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>jsonp处理</title>
</head>

<body>
  <h3 id="h3">获取张三信息</h3>

  <div id="user">

  </div>

  <!-- jsonp实现跨域请求 -->
  <script>
    h3.onclick = function () {
      let script = document.createElement('script')
      script.src = 'http://localhost:3000/?cb=showUserinfo&a='+Math.random()
      document.body.appendChild(script)
    }


    function showUserinfo({ id, name }) {
      let html = `
        <li>id:${id}</li>
        <li>name:${name}</li>
      `
      user.innerHTML = html;
    }
  </script>
  <!-- script中的src是可以跨域请求 -->
  <!-- <script src="http://localhost:3000/?cb=showUserinfo"></script> -->
  <script src="http://localhost:3000/?cb=kefu"></script>

</body>

</html>